package cn;

import java.sql.*;
import java.net.*;
import java.io.*;
import java.util.*;

/*
 *	F405-37/10.203.73.37 当前ip地址
 *
 */

public class MysqlTest0 {
	public static void main(String args[]) throws IOException, SQLException {
		Scanner in = new Scanner(System.in);
		Connection con;
		String sql;
		Statement stmt;
		int num;
		String name, sex;
		int age;
		String sDBDriver = "oracle.jdbc.driver.OracleDriver";
		String sConnStr = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
		try {	
			Class.forName("oracle.jdbc.driver.OracleDriver");
		} catch (java.lang.ClassNotFoundException e) {
			System.err.print("ClassNotFoundException: ");
			System.err.println(e.getMessage());
		}
		try {
			con = DriverManager.getConnection(sConnStr, "system", "system");
			stmt = con.createStatement();
			// 向student表中插入一行录记录
			sql = "INSERT INTO STUDENT " + "VALUES(1235,'xxx','男',20)";
			stmt.executeUpdate(sql);

			// 检索student表中的所有记录并获取数据输出。
			sql = " SELECT * FROM STUDENT";
			ResultSet rs = stmt.executeQuery(sql);

			System.out.println("\n\n\n");
			System.out.println("   学号  姓名 性别  年龄");
			System.out.println("   ----------------------");

			// 取出结果集rs中的所有记录
			while (rs.next()) {
				num = rs.getInt(1); // 取出当前行第1列数据
				name = rs.getString(2); // 取出当前行第2列数据
				sex = rs.getString(3);
				age = rs.getInt(4);
				System.out.println("   " + num + "   " + name + "  " + sex
						+ "  " + age);
			}

			// 关闭连接。
			stmt.close();
			con.close();
		} catch (SQLException ex) {
			System.err.println("SQLException: " + ex.getMessage());
		}
		in.close();
	}
}


